home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / WASTE 1.2a4 / WASTE Demo / WEDemoIntf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-05  |  10.1 KB  |  436 lines  |  [TEXT/CWIE]

  1. /*
  2.     WASTE Demo Project:
  3.     Demo Header
  4.         
  5.     Copyright © 1993-1995 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11. /*
  12.     Due to differences between Pascal and C, this file (nothing like it originally existed
  13.     in the original Pascal code) was neccessary to create.  In it contains various macros,
  14.     constants, type and class declarations, function prototypes, etc..  From the original
  15.     code, some of this material would be spread amongst the source files, but a good
  16.     majority of this file comes from the WEDemoIntf.p file (the declarations, constants, etc).
  17.     There still is a WEDemoIntf.c file in the project tho since the .p file had a few
  18.     utility functions declared and defined in it.
  19. */
  20.  
  21. #ifndef __WEDEMOAPP__
  22. #define __WEDEMOAPP__
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27. #ifndef __RESOURCES__
  28. #include <Resources.h>
  29. #endif
  30. #ifndef __QUICKDRAW__
  31. #include <QuickDraw.h>
  32. #endif
  33. #ifndef __MENUS__
  34. #include <Menus.h>
  35. #endif
  36. #ifndef __WINDOWS__
  37. #include <Windows.h>
  38. #endif
  39. #ifndef __CONTROLS__
  40. #include <Controls.h>
  41. #endif
  42. #ifndef __STANDARDFILE__
  43. #include <StandardFile.h>
  44. #endif
  45. #ifndef _WASTE_
  46. #include "WASTE.h"
  47. #endif
  48. #ifndef _LIMITS
  49. #include "limits.h"
  50. #endif
  51.  
  52.  
  53. /*
  54.  *    Some utility macros.
  55.  */
  56.  
  57.  
  58.  
  59. //     "Originally," these are things built into the Pascal language
  60. //     but since C doesn't have anything like them, and in an attempt to keep the code readable
  61. //     and similar to the original Pascal source, these #define macros work nice.
  62.  
  63.  
  64. #define BTST( FLAGS, BIT )    (((FLAGS) & (1L << (BIT))) ? 1 : 0)
  65. #define BSET( FLAGS, BIT )  ((FLAGS) |= (1L << (BIT)))
  66. #define BCLR( FLAGS, BIT )  ((FLAGS) &= (~(1L << (BIT))))
  67.  
  68. #define ABS(A) ((A) > 0 ? (A) : -(A))
  69.  
  70. #define BSL(A, B)    (((long)A) << (B))
  71. #define BSR(A, B)    (((long)A) >> (B))
  72. #define BOR(A, B)    ( A | B )
  73. #define BAND(A, B)    ( A & B )
  74.  
  75. #ifndef HiWrd
  76. #define HiWrd(aLong)        (((aLong) >> 16) & 0xFFFF )
  77. #endif
  78. #ifndef LoWrd
  79. #define LoWrd(aLong)        ((aLong) & 0xFFFF )
  80. #endif
  81.  
  82. //    WASTE Demo signature
  83.  
  84. #define kAppSignature     'OEDE'
  85.  
  86. //    resource types, clipboard types, and file types
  87.  
  88. #define    kTypeDeskAccessory        'DRVR'
  89. #define    kTypeFont                'FONT'
  90. #define    kTypePicture            'PICT'
  91. #define    kTypeSound                'snd '
  92. #define kTypeSoup                'SOUP'
  93. #define kTypeStyles                'styl'
  94. #define kTypeText                'TEXT'
  95. #define kTypeTextReadOnly        'ttro'
  96.  
  97. //    virtual key codes for navigation keys found on extended keyboards
  98.  
  99. #define    keyPgUp        0x74
  100. #define keyPgDn        0x79
  101. #define keyHome        0x73
  102. #define keyEnd        0x77
  103.  
  104. //    virtual key codes generated by some function keys
  105.  
  106. #define    keyF1        0x7A
  107. #define keyF2        0x78
  108. #define keyF3        0x63
  109. #define keyF4        0x76
  110.  
  111. //    possible values for HandleOpenDocument refCon parameter
  112.  
  113. enum {
  114.     kDoOpen        = 0,
  115.     kDoPrint    = 1
  116. };
  117.  
  118. //     other commonly used constants
  119.  
  120. #define    kBarWidth        16        // width of a scroll bar
  121. #define kTitleHeight    20        // usual height of a window title bar
  122. #define kTextMargin        3        // indent of text rect from a window port rect
  123. #define kScrollDelta    11        // pixels to scroll when the scroll bar arrow is clicked
  124.  
  125. #define kMinSystemVersion        0x0700    // system 7
  126. #define kScrapThreshold            4 * 1024
  127.  
  128. // enumeration types used for closing a window and/or quitting the application
  129.  
  130. typedef enum {closingWindow, closingApplication} ClosingOption;
  131. typedef enum {savingYes, savingNo, savingAsk} SavingOption;
  132.  
  133.  
  134. /*
  135.  *    Resource ID numbers
  136.  */
  137.  
  138. // menu IDs
  139.  
  140. enum {
  141.     kMenuApple        = 1,
  142.     kMenuFile,
  143.     kMenuEdit,
  144.     kMenuFont,
  145.     kMenuSize,
  146.     kMenuStyle,
  147.     kMenuColor,
  148.     kMenuFeatures,
  149.     kMenuAlignment
  150. };
  151.  
  152. //    Apple Menu items
  153.  
  154. enum {
  155.     kItemAbout        = 1
  156. };
  157.  
  158. //    File menu items
  159.  
  160. enum {
  161.     kItemNew        = 1,
  162.     kItemOpen        = 2,
  163.     kItemClose        = 4,
  164.     kItemSave        = 5,
  165.     kItemSaveAs        = 6,
  166.     kItemQuit        = 8
  167. };
  168.  
  169. //    Edit menu items
  170.  
  171. enum {
  172.     kItemUndo        = 1,
  173.     kItemCut        = 3,
  174.     kItemCopy        = 4,
  175.     kItemPaste        = 5,
  176.     kItemClear        = 6,
  177.     kItemSelectAll    = 7
  178. };
  179.  
  180. //    Size menu items
  181.  
  182. enum {
  183.     kItemLastSize    = 6,
  184.     kItemSmaller    = 8,
  185.     kItemLarger        = 9
  186. };
  187.  
  188. //    Style menu items
  189.  
  190. enum {
  191.     kItemPlainText    = 1,
  192.     kItemBold,
  193.     kItemItalic,
  194.     kItemUnderline,
  195.     kItemOutline,
  196.     kItemShadow,
  197.     kItemCondensed,
  198.     kItemExtended
  199. };
  200.  
  201. //    Color menu items
  202.  
  203. enum {
  204.     kItemBlack        = 1,
  205.     kItemRed,
  206.     kItemGreen,
  207.     kItemBlue,
  208.     kItemCyan,
  209.     kItemMagenta,
  210.     kItemYellow
  211. };
  212.  
  213. //    Alignment menu items
  214.  
  215. enum {
  216.     kItemAlignDefault    = 1,
  217.     kItemAlignLeft        = 3,
  218.     kItemCenter,
  219.     kItemAlignRight,
  220.     kItemJustify
  221. };
  222.  
  223. //    Features menu items
  224.  
  225. enum {
  226.     kItemAlignment        = 1,
  227.     kItemTabHooks,
  228.     kItemAutoScroll        = 4,
  229.     kItemOutlineHilite,
  230.     kItemReadOnly,
  231.     kItemIntCutAndPaste,
  232.     kItemDragAndDrop,
  233.     kItemOffscreenDrawing
  234. };
  235.  
  236.  
  237. //    Alert & dialog template resource IDs
  238.  
  239. enum {
  240.     kAlertNeedSys7        = 128,
  241.     kAlertGenError        = 130,
  242.     kAlertSaveChanges    = 131,
  243.     kDialogAboutBox        = 256
  244. };
  245.  
  246. //    String list resource IDs
  247.  
  248. enum {
  249.     kUndoStringsID        = 128,
  250.     kClosingQuittingStringsID
  251. };
  252.  
  253. // miscellaneous resource IDs
  254.  
  255. enum {
  256.     kMenuBarID                = 128,
  257.     kWindowTemplateID        = 128,
  258.     kScrollBarTemplateID    = 128,
  259.     kPromptStringID            = 128
  260. };
  261.  
  262. /*
  263.     With the declaration of the ScrollBarPair type, there was some Pascal-specific things
  264.     that Marco did, so I took a little bit of liberty.  I could more easily consolodate
  265.     things, but I'm trying to maintain as much similarity to the original code as possible
  266.     (i.e. just axe the ScrollBarPair struct and put it all in the DocumentRec struct)
  267. */
  268.  
  269.  
  270. // a ScrollBarPair is just a pair of control handles.
  271.  
  272. struct ScrollBarPair
  273. {
  274.     ControlRef    v;
  275.     ControlRef    h;
  276. };
  277.  
  278. typedef struct ScrollBarPair ScrollBarPair, *ScrollBarPairPtr, **ScrollBarPairHandle;
  279.  
  280. // a DocumentRecord is a structure associated with each window
  281. // a handle to this structure is kept in the window refCon
  282.  
  283. struct DocumentRecord
  284. {
  285.     WindowRef            owner;                // the window
  286.     ScrollBarPair         scrollBars;            // its scroll bars
  287.     WEReference         we;                    // its WASTE instance
  288.     Handle                 fileAlias;            // alias to associated file
  289. };  // DocumentRec
  290.  
  291. typedef struct DocumentRecord DocumentRecord, *DocumentPtr, **DocumentHandle;
  292.  
  293.  
  294. /*
  295.  *    The external declaration of some global variables.
  296.  */
  297.  
  298. //  These are defined in WEDemoIntf.c
  299.  
  300. extern    Boolean        gHasColorQD;        // true if Color QuickDraw is available
  301. extern    Boolean        gHasDragAndDrop;    // true if Drag Manager is available
  302. extern    Boolean        gHasTextServices;    // true is the Text Services Manager is available
  303. extern    Boolean        gExiting;            // set this variable to drop out of the event loop and quit
  304.  
  305. //    These are defined in WEDemoEvents.c
  306.  
  307. extern    unsigned long    gSleepTime;            // sleep time for WaitNextEvent
  308. extern    RgnHandle        gMouseRgn;            // mouse region for WaitNextEvent
  309.  
  310. /*
  311.  *    Function Prototypes
  312.  */
  313.  
  314. //    From DialogUtils.c
  315.  
  316. pascal Boolean    MyStandardDialogFilter( DialogRef, EventRecord *, short * );
  317. pascal ModalFilterUPP    GetMyStandardDialogFilter( void );
  318. short            GetDialogItemType( DialogRef, short );
  319. Handle            GetDialogItemHandle( DialogRef, short );
  320. void            GetDialogItemRect( DialogRef, short, Rect * );
  321. pascal void        SetDialogItemProc( DialogRef, short, UserItemUPP );
  322.  
  323. //    From LongControls.c 
  324.  
  325. OSErr            LCAttach( ControlRef );
  326. void            LCDetach( ControlRef );
  327. void            LCSetValue( ControlRef, long );
  328. void            LCSetMin( ControlRef, long );
  329. void            LCSetMax( ControlRef, long );
  330. long            LCGetValue( ControlRef );
  331. long            LCGetMin( ControlRef );
  332. long            LCGetMax( ControlRef );
  333. void            LCSynch( ControlRef );
  334.  
  335.  
  336. //    From WEDemoIntf.c
  337.  
  338. DocumentHandle    GetWindowDocument(WindowRef);
  339. #if __cplusplus
  340. inline WEReference GetWindowWE(WindowRef window) { return (* GetWindowDocument(window))->we; }
  341. #else
  342. #define GetWindowWE(window) (* GetWindowDocument(window))->we
  343. #endif
  344. void            ErrorAlert( OSErr );
  345. void            ForgetHandle( Handle * );
  346. void            ForgetResource( Handle * );
  347. OSErr            NewHandleTemp( Size, Handle * );
  348. void            PStringCopy( ConstStr255Param, Str255 );
  349.  
  350. //    From WEDemoAbout.c
  351.  
  352. OSErr            WETextBox( short, const Rect *, short );
  353. void            DoAboutBox( short );
  354.  
  355. //    From WEDemoDrags.c
  356.  
  357. pascal OSErr    MyTrackingHandler( DragTrackingMessage, WindowRef, void *, DragReference );
  358. pascal OSErr    MyReceiveHandler( WindowRef, void *, DragReference );
  359.  
  360.  
  361. //    From WEDemoEvents.c
  362.  
  363. void            AdjustCursor( Point, RgnHandle );
  364. void            DoMouseDown( const EventRecord * );
  365. void            DoKeyDown( const EventRecord * );
  366. void            DoDiskEvent( const EventRecord * );
  367. void            DoOSEvent( const EventRecord * );
  368. void            DoHighLevelEvent( const EventRecord * );
  369. void            DoNullEvent( const EventRecord * );
  370. void            DoWindowEvent( const EventRecord *);
  371. void            ProcessEvent( void );
  372. OSErr            GotRequiredParams( const AppleEvent * );
  373. OSErr            InitializeEvents( void );
  374.  
  375. // from WEDemoFiles.c
  376.  
  377. OSErr            ReadTextFile( const FSSpec *, WEReference );
  378. OSErr            WriteTextFile( const FSSpec *, WEReference );
  379. pascal OSErr    TranslateDrag( DragReference, ItemReference, FlavorType, Handle );
  380. pascal OSErr    CheckObjectLock( short, long, StringPtr );
  381. pascal OSErr    FSpCheckObjectLock( const FSSpec * );
  382.  
  383. // from WEDemoInit.c
  384.  
  385. OSErr            Initialize( void );
  386. void            Finalize( void );
  387.  
  388. // from WEDemoMenus.c
  389.  
  390. void            SetDefaultDirectory( const FSSpec * );
  391. pascal Boolean    MySFDialogFilter( DialogRef, EventRecord *, short *, void * );
  392. pascal ModalFilterYDUPP    GetMySFDialogFilter( void );
  393. short            FindMenuItemText( MenuRef, ConstStr255Param );
  394. Boolean            EqualColor( const RGBColor *, const RGBColor * );
  395. void            PrepareMenus( void );
  396. void            DoDeskAcc( short );
  397. OSErr            DoNew( void );
  398. OSErr            DoOpen( void );
  399. OSErr            SaveWindow( const FSSpec *, WindowRef );
  400. OSErr            DoSaveAs( const FSSpec *, WindowRef );
  401. OSErr            DoSave( WindowRef );
  402. OSErr            DoClose( ClosingOption, SavingOption, WindowRef );
  403. OSErr            DoQuit( SavingOption );
  404. void            DoAppleChoice( short );
  405. void            DoFileChoice( short );
  406. void            DoEditChoice( short );
  407. void            DoFontChoice( short );
  408. void            DoSizeChoice( short );
  409. void            DoStyleChoice( short );
  410. void            DoColorChoice( short );
  411. void            DoAlignChoice( short );
  412. void            DoFeatureChoice( short );
  413. void            DoMenuChoice( long );
  414. OSErr            InitializeMenus( void );
  415.  
  416. // from WEDemoScripting.c
  417.  
  418. OSErr            WEGetContentsDesc( long, long, Boolean, AEDesc *, WEReference );
  419. OSErr            WESetContentsDesc( long, long, const AEDesc *, WEReference );
  420. OSErr            InstallCoreHandlers( void );
  421.  
  422. // from WEDemoWindows.c
  423.  
  424. void            DoDrag( Point, WindowRef );
  425. void            DoGrow( Point, WindowRef );
  426. void            DoZoom( short, WindowRef );
  427. Boolean            DoContent( Point, const EventRecord *, WindowRef );
  428. void            DoKey( char, const EventRecord * );
  429. void            DoUpdate( WindowRef );
  430. void            DoActivate( Boolean, WindowRef );
  431. OSErr            CreateWindow( const FSSpec * );
  432. void            DestroyWindow( WindowRef );
  433. void            Resize( Point, WindowRef );
  434.  
  435.  
  436. #endif /* __WEDEMOAPP__ */